package cn.hrc.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect // 切面
public class CalcRuntime {
    /** execution(* cn.hrc.service.*.*(..)) */
    @Around(value = "execution(* cn.hrc.service.impl.*.*(..))")// *表示所有方法
    public Object around(ProceedingJoinPoint joinPoint)  {
        // 获取方法执行前的时间
        long t1 = System.currentTimeMillis();
        Object proceed = null;
        try {
            // 执行方法
            proceed = joinPoint.proceed();
            // 获取方法执行后的时间
        } catch (Throwable e) {
            System.out.println("异常捕获:"+e.getMessage());
        }finally {
            long t2 = System.currentTimeMillis();
            System.out.println("运行时间："+(t2-t1));
        }
        return proceed;
    }
}
